﻿namespace gisgeb.plugins.projectfolder
{
    using System.IO;
    using System.Windows.Forms;

    /// <summary>
    /// Description of ProjectFolderCreator.
    /// </summary>
    internal class ProjectFolderCreator
    {
        private const string MESSAGE_TITLE = "gisgeb ProjectStructureCreator plugin";

        internal void CreateStructureAt(string directory)
        {
            if (!Directory.Exists(directory))
            {
                MessageBox.Show(
                    string.Format("{0}\nIs not an existing directory.\nHowever you managed this, I can't do a thing...", directory), 
                    MESSAGE_TITLE,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            if (Directory.GetFiles(directory).Length > 0)
            {
                DialogResult answer = MessageBox.Show(
                    string.Format("{0}\nIs not emty.\nDo you really want to create a project folder structure here?", directory),
                    MESSAGE_TITLE,
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question
                    );
                if (answer != DialogResult.Yes)
                {
                    return;
                }
            }

            string[] directories = new[]
                                   { 
                                    "source",
                                    "bin",
                                    "build",
                                    "lib",
                                    "resource",
                                    };

            foreach (var dirName in directories)
            {
                string newFolder = Path.Combine(directory, dirName);
                Directory.CreateDirectory(newFolder);
            }
        }
    }
}